import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomTransactionProperty } from '@/shared/model/room-transaction-property.model';
import RoomTransactionPropertyService from './room-transaction-property.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomTransactionPropertyDetails extends Vue {
  @Inject('roomTransactionPropertyService') private roomTransactionPropertyService: () => RoomTransactionPropertyService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomTransactionProperty: IRoomTransactionProperty = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomTransactionPropertyId) {
        vm.retrieveRoomTransactionProperty(to.params.roomTransactionPropertyId);
      }
    });
  }

  public retrieveRoomTransactionProperty(roomTransactionPropertyId) {
    this.roomTransactionPropertyService()
      .find(roomTransactionPropertyId)
      .then(res => {
        this.roomTransactionProperty = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
